import { Command } from "commander";
import { ethers } from "ethers";
import { BridgeToken__factory } from "@peersyst/xrp-evm-contracts/dist/typechain/factories/BridgeToken__factory";
import { Log, LogStatus, LogType } from "../util/Logger";

const program = new Command("deploy-token")
    .option("-w, --wallet-seed <value>", "Wallet seed")
    .option("-t, --token-code <value>", "Token code")
    .option("-n, --node <value>", "The network node", "https://rpc-evm-sidechain.peersyst.tech")
    .action(async ({ node, walletSeed, tokenCode }) => {
        if (node && walletSeed && tokenCode) {
            try {
                const provider = new ethers.providers.JsonRpcProvider(node);
                const signerWallet = new ethers.Wallet(walletSeed, provider);

                Log(LogType.Tool, LogStatus.ToDo, `Deploying BridgeToken with code ${tokenCode}...`);
                const bridgeTokenFactory = new BridgeToken__factory(signerWallet);
                const bridgeToken = await bridgeTokenFactory.deploy(tokenCode, `Token ${tokenCode}`);

                Log(LogType.Tool, LogStatus.Done, `BridgeToken deployed successfully to address ${bridgeToken.address}`);
            } catch (error) {
                console.log(error);
                process.exit(1);
            }
            process.exit(0);
        } else {
            program.help();
            process.exit(1);
        }
    });
export default program;
